home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / gnu_tile_forth.lha / tst / colburn-sieve.tst < prev    next >
Text File  |  1992-05-19  |  1KB  |  41 lines

  1. .( Loading Colburn Sieve benchmark...) cr
  2.  
  3. \ This is the "Colburn Sieve" as published in a letter to the editor
  4. \ of Dr. Dobbs' Journal.  It is the same algorithm as the first, but
  5. \ is a better Forth implementation of the algorithm.  It uses a
  6. \ DO .. LOOP in the inner loop instead of  BEGIN .. WHILE .. REPEAT
  7. \ This version is a more fair comparison of Forth in relation to other
  8. \ languages.  For comparisons between different Forth systems, both
  9. \ versions are widely used.  It is necessary to state which version
  10. \ you are using in order for your benchmark to be useful.
  11. \
  12. \ The Colburn Sieve typically runs in about 60% of the time of the
  13. \ Byte sieve.
  14.  
  15. decimal
  16.  
  17. 8192 constant size ( -- int)
  18. create flags ( -- addr) size allot
  19.  
  20. : do-prime ( -- )
  21.   flags  size 1 fill 
  22.   0 size 0 do
  23.     flags i + c@
  24.     if 3 i + i + dup i + size <
  25.       if size flags +
  26.     over i + flags + do
  27.       0 i c! dup
  28.     +loop
  29.       then
  30.       drop 1+
  31.    then
  32.  loop
  33.  1899 = not abort" prime: wrong result"
  34.  
  35. : colburn-sieve ( -- )
  36.   10 0 do do-prime loop
  37. ;
  38.  
  39. forth only
  40.